<template>
	<view>
		<tn-nav-bar :isBack='true' :backTitle='" "' :bottomShadow='false' :alpha="alpha">我的业绩</tn-nav-bar>
		<image src="/static/product/topbg.png" class="topbg" mode=""></image>
		<view :style="{paddingTop: vuex_custom_bar_height + 'px'}" class="con">
			<tn-sticky :customNavHeight='vuex_custom_bar_height'>
				<view class="tabs" :style="{background:!alpha?'#fff':''}">
					<view class="tabs__box">
						<image src="/static/sy/tab1.png" class="tabs__box__bg" v-if="current==0" mode=""></image>
						<image src="/static/sy/tab2.png" class="tabs__box__bg" v-if="current==1" mode=""></image>
						<view class="tabs__box__item" @click="change(index)"
							style="width: 50%;position: relative;height: 100%;" v-for="(item,index) in list"
							:key="index">

						</view>
					</view>
					<view class="time" @click="show=true">
						{{time}}
						<text class="tn-icon-down-triangle" style="color: #888888;"></text>
					</view>
				</view>
			</tn-sticky>
			<loading v-if="loading"></loading>
			<view class="list" v-else>
				<view class="list__item">
					<image src="/static/my/sybg.png" class="list__item__bg" mode=""></image>
					<view class="list__item__box">
						<view class="list__item__box__title">
							<image src="/static/my/syicon.png" class="list__item__box__icon" mode=""></image>
							总业绩
						</view>
						<view class="tn-flex tn-flex-col-center">
							<view class="list__item__box__item">
								<view class="list__item__box__value">
									{{info.teamPrice}}
								</view>
								<view class="list__item__box__text">
									团队交易额(元）
								</view>
							</view>
							<view class="list__item__box__item">
								<view class="list__item__box__value">
									{{info.teamCount}}
								</view>
								<view class="list__item__box__text">
									团队新增用户(人）
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="list__item">
					<image src="/static/my/sybg.png" class="list__item__bg" mode=""></image>
					<view class="list__item__box">
						<view class="list__item__box__title">
							<image src="/static/my/syicon.png" class="list__item__box__icon" mode=""></image>
							个人业绩
						</view>
						<view class="tn-flex tn-flex-col-center">
							<view class="list__item__box__item">
								<view class="list__item__box__value">
									{{info.myPrice}}
								</view>
								<view class="list__item__box__text">
									个人交易额(元）
								</view>
							</view>
							<view class="list__item__box__item">
								<view class="list__item__box__value">
									{{info.totalCount}}
								</view>
								<view class="list__item__box__text">
									个人新增用户(人）
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="tn-safe-area-inset-bottom">

			</view>

		</view>
		<tn-picker mode="time" v-model="show" :params="params" :endYear='(new Date).getFullYear()' @confirm='confirm'
			@cancel='show=false'></tn-picker>
	</view>
</template>

<script>
	import user from '@/api/_user.js'
	export default {
		data() {
			return {
				list: [{
					status: 1
				}, {
					status: 2
				}],
				status: 1,
				current: 0,
				alpha: true,
				startTime: "",
				endTime: "",
				info: {},
				time: '',
				show: false,
				params: {
					year: true,
					month: true,
					day: false,
					hour: false,
					minute: false,
					second: false
				},
				loading:true
			};
		},
		methods: {
			change(index) {
				this.current = index;
				this.status = this.list[index].status
				this.$forceUpdate()
				if (index == 0) { //当月
					this.startTime = this.timeFormat((new Date()).getTime(), 'yyyy-mm') + '-01' + ' 00:00:00'
					this.endTime = this.timeFormat((new Date()).getTime(), 'yyyy-mm') + '-31' + ' 23:59:59'
				}
				if (index == 1) { //当月
					this.startTime = this.timeFormat((new Date()).getTime(), 'yyyy-mm-dd') + ' 00:00:00'
					this.endTime = this.timeFormat((new Date()).getTime(), 'yyyy-mm-dd') + ' 23:59:59'
				}
				this.time=this.timeFormat((new Date()).getTime(), 'yyyy-mm')
				this.getdata()
			},
			confirm(e) {
				this.time=e.year+'-'+e.month
				this.startTime = e.year + '-' + e.month + '-' + '-01' + ' 00:00:00'
				this.endTime = e.year + '-' + e.month + '-' + '-31' + ' 23:59:59'
				this.show=false
				this.getdata()
			},
			getdata() {
				this.loading=true
				user.myPerformance({
					startTime: this.startTime,
					endTime: this.endTime
				}).then(res => {
					if (res.data.code == 1) {
						this.info = res.data.data
						this.loading=false
					}
				})
			}
		},
		onLoad() {
			this.startTime = this.timeFormat((new Date()).getTime(), 'yyyy-mm') + '-01' + ' 00:00:00'
			this.endTime = this.timeFormat((new Date()).getTime(), 'yyyy-mm') + '-31' + ' 23:59:59'
			this.getdata()
			this.time = this.timeFormat((new Date()).getTime(), 'yyyy-mm')
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F4F4F4;
	}

	.tabs {
		// border-top: 2rpx solid #F4F6F8;
		padding: 30rpx 0 0;

		&__box {
			display: flex;
			align-items: center;
			position: relative;
			width: 750rpx;
			height: 115rpx;

			// background-color: #fff;
			&__bg {
				width: 750rpx;
				height: 115rpx;
				position: absolute;
				top: 0;
				left: 0;
			}
		}
	}

	.con {
		position: relative;
	}

	.list {
		padding: 32rpx 30rpx;
		border-radius: 30rpx;
		margin-top: -30rpx;
		background-color: #F4F4F4;

		&__item {
			width: 690rpx;
			height: 249rpx;
			background: #FFFFFF;
			border-radius: 36rpx;
			position: relative;
			overflow: hidden;
			margin-bottom: 30rpx;

			&__bg {
				width: 690rpx;
				height: 249rpx;
				position: absolute;
				top: 0;
				left: 0;
			}

			&__box {
				position: relative;

				&__title {
					font-family: PingFang SC;
					font-weight: 800;
					font-size: 26rpx;
					color: #1E1E1E;
					line-height: 26rpx;
					display: flex;
					align-items: center;
					padding: 44rpx 0 0 32rpx;

				}

				&__icon {
					width: 27rpx;
					height: 31rpx;
					margin-right: 13rpx;
				}

				&__item {
					padding: 54rpx 0 0 30rpx;
					width: 40%;

				}

				&__value {
					font-family: DINNextLTPro-Bold;
					font-weight: bold;
					font-size: 48rpx;
					color: #1E1E1E;
					line-height: 48rpx;
				}

				&__text {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #95979B;
					line-height: 24rpx;
					margin-top: 16rpx;
				}
			}
		}
	}

	.time {
		padding: 30rpx 30rpx 50rpx;
		background: #FFFFFF;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 24rpx;
		color: #888888;
		line-height: 24rpx;
	}
</style>